<script setup>
import { onMounted, ref, reactive } from "vue";
import { getSongListClass,getSelectedPlaylistClass,getSelectedSongList } from '../../../api/songList'
import SongCard from '../../../components/songCard.vue'

const tags = ref([])
const tagActive = ref(0)
const playLists = ref([])
const queryFrom = reactive({
  before: 0,
  limit: 50,
  order: '', // hot new
})

const switchClass = (id) => {
  tagActive.value = id
  selectedSongList()
}

const songListClass = () => {
  getSelectedPlaylistClass().then(res => {
    tags.value = res.tags
    tagActive.value = res.tags[0].id
    selectedSongList()
  })
}

const selectedSongList = () => {
  const {before,limit} = queryFrom
  const query = {
    limit,
    cat: 1
  }
  if(before) {
    query.before = before
  }
  getSelectedSongList(query).then(res => {
    playLists.value = res.playlists
  })
}

onMounted(() => {
  songListClass()
})
</script>

<template>
  <div class="tags">
    <div
      v-for="(item,index) in tags" :key="index"
      :class="`tag-item ${tagActive === item.id ? 'tags-active' : ''}`"
      @click="switchClass(item.id)"
    >
      {{ item.name }}
    </div>
    <div class="tag-item">
      <span>更多</span>
      <span class="iconfont icon-xiangxia2"></span>
    </div>
  </div>

  <div class="playlist">
    <div v-for="item in playLists" :key="item.id" class="playlist-item">
      <song-card :item="item"/>
    </div>
  </div>
</template>

<style scoped lang="scss">
@mixin boxCenter {
  display: flex;
  justify-content: center;
  align-items: center;
}
.tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}
.tag-item {
  min-width: 80px;
  height: 40px;
  border: 1px solid #1e90ff;
  color: #1e90ff;
  font-size: 14px;
  letter-spacing: 1px;
  border-radius: 50px;
  @include boxCenter;
  margin-right: 12px;
  margin-top: 8px;
  cursor: pointer;
  .iconfont {
    font-size: 12px;
    margin-left: 4px;
  }
  &:hover {
    background: #1e90ff;
    color: #fff;
    border: none;
  }
}
.tags-active {
  color: #fff;
  border: none;
  background: #1e90ff;
  &:hover {
    background: #1e90ff;
    color: #fff;
    border: none;
  }
}

.playlist {
  display: flex;
  flex-wrap: wrap;
}
.playlist-item {
  margin-top: 12px;
  margin-right: 12px;
}
</style>
